package com.quanyue.haircut.shop.controller;

import com.quanyue.auto.util.ServiceResult;
import com.quanyue.auto.web.Principal;
import com.quanyue.auto.web.Scope;
import com.quanyue.haircut.domain.constant.UserRole;
import com.quanyue.haircut.domain.entity.TechnicianAssess;
import com.quanyue.haircut.shop.dto.AssessDetail;
import com.quanyue.haircut.shop.dto.AssessRequest;
import com.quanyue.haircut.shop.service.AssessService;
import com.vhuomai.mybatis.mapper.page.Page;
import com.vhuomai.mybatis.mapper.page.PageRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

@Api(tags = "会员消费评价")
@RestController
@RequestMapping("/api")
public class AssessController {
    @Autowired
    private AssessService assessService;

    @ApiOperation(value = "添加评价信息")
    @Scope(role = UserRole.USER)
    @PostMapping(value = "/assess", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <Boolean> createAssess(@RequestBody AssessRequest assessRequest,
                                                @ApiIgnore Principal principal) {
        TechnicianAssess technicianAssess = new TechnicianAssess();
        technicianAssess.setMerchantNo(principal.getMerchantNo());
        technicianAssess.setUserId(principal.getId());
        technicianAssess.setContent(assessRequest.getContent());
        technicianAssess.setStarCount(assessRequest.getStarCount());
        technicianAssess.setTechnicianId(assessRequest.getTechnicianId());
        assessService.createAssess(assessRequest, technicianAssess);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "评价列表(根据技师Id查询所有评价)")
    @PostMapping(value = "/assess/page", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <Page <AssessDetail>> createAssess(@RequestBody PageRequest request,
                                                            @RequestParam Integer technicianId) {
        return ServiceResult.success(assessService.findAssessList(request, technicianId));
    }
}
